<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        .box {
            width: 800px;
            height: 600px;
           background-color:  hotpink;
            /* margin: 0 auto; */
            /* margin-top: 50px; */
            position: relative;
        }

        .box .dv {
            width: 100px;
            height: 100px;
            border-radius: 50%;
            background-color: lawngreen;
            position: absolute;
            left: 0;
            top: 0;
        }
    </style>
</head>
<body>
    <button>点击开始运动</button>
    <div class="box">
        <div class="dv"></div>
    </div>
    <script src="utils.js"></script>
    <script>
        const btn = my$('button')[0]
        const dv = my$('.dv')[0]
        on(btn,'onclick',function(){
            let leftt = 5,
                topp = 5
            setInterval(function(){
               dv.style.left =  dv.offsetLeft + leftt + 'px'
               dv.style.top = dv.offsetTop + topp + 'px'
               if(dv.offsetLeft >= 700 || dv.offsetLeft <= 0){leftt *= -1}
               if(dv.offsetTop >= 500 || dv.offsetTop <= 0){topp *= -1}
            },10)
        })
    </script>
</body>
</html>